package main

import (
	"downloader/internal/httpclient"
	"encoding/json"
	"fmt"
	"io"
	"sync"
)

var maxdo int64

func main() {
	var wg sync.WaitGroup

	i := 0
	limit := 1
	for {
		wg.Add(1)
		go func(wg *sync.WaitGroup) {
			defer wg.Done()
			ab2()
		}(&wg)
		i++
		if i%limit == 0 && i != 0 {
			fmt.Print(i, "\r\n")
			wg.Wait()
		}
	}

}

func ab1() {
	jsonData := `{"type":"event","payload":{"website":"260000c2-ea0e-491d-9460-f39cbcd849b4","hostname":"www.clgod123.com","screen":"1920x1080","language":"zh-CN","title":"2025%E7%BE%8E%E5%9B%BD%E7%94%B5%E5%BD%B1%E3%80%8A%E6%AD%BB%E7%A5%9E%E6%9D%A5%E4%BA%866%EF%BC%9A%E8%A1%80%E8%84%89%E8%AF%85%E5%92%92%E3%80%8B%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E5%A4%B8%E5%85%8B%E7%BD%91%E7%9B%98%E4%B8%8B%E8%BD%BD%E3%80%8C%E9%AB%98%E6%B8%85%E7%89%88%E3%80%8D%E5%AE%8C%E6%95%B4%E7%89%88-%E7%A3%81%E5%8A%9B%E5%A4%A9%E5%A0%82","url":"/movie/131438.html"}}`

	// 定义根接口为 map，键为 string，值为 interface{}
	var data map[string]interface{}

	// 解析 JSON 到 map
	if err := json.Unmarshal([]byte(jsonData), &data); err != nil {
		panic(err)
	}
	urlStr := "https://tt.mandudu.com/api/send"
	config := httpclient.DefaultConfig()
	client := httpclient.New(config)
	request := client.Post(urlStr)
	request.WithJSON(data)
	request.WithHeader("Origin", "https://www.clgod123.com")
	request.WithHeader("referer", "https://www.clgod123.com/")
	request.WithHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36")

	resp, respErr := client.Do(request)
	if respErr != nil {
		fmt.Println(respErr.Error())
		return
	}
	defer resp.Body.Close()
	body, bodyErr := io.ReadAll(resp.Body)
	if bodyErr != nil {
		fmt.Println(bodyErr.Error())
	}
	fmt.Println(maxdo, ":", string(body))
	maxdo++
}

func ab2() {

	urlStr := "https://www.clgod123.com/list/0-28-0-0.html"
	config := httpclient.DefaultConfig()
	client := httpclient.New(config)
	request := client.Post(urlStr)
	// request.WithJSON(data)
	// request.WithHeader("Origin", "https://www.clgod123.com")
	// request.WithHeader("referer", "https://www.clgod123.com/")
	// request.WithHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36")

	resp, respErr := client.Do(request)
	if respErr != nil {
		fmt.Println(respErr.Error())
		return
	}
	defer resp.Body.Close()
	body, bodyErr := io.ReadAll(resp.Body)
	if bodyErr != nil {
		fmt.Println(bodyErr.Error())
	}
	fmt.Println(maxdo, ":", string(body))
	maxdo++
}
